<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>返回给定的日期与地点的日出时间</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.date-sun-info.html">« date_sun_info</a></li>
      <li style="float: right;"><a href="function.date-sunset.html">date_sunset »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.datetime.html">Date/Time 函数</a></li>
    <li>返回给定的日期与地点的日出时间</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.date-sunrise" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">date_sunrise</h1>
  <p class="verinfo">(PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">date_sunrise</span> &mdash; <span class="dc-title">返回给定的日期与地点的日出时间</span></p>

 </div>

 <div id="function.date-sunrise-refsynopsisdiv">
  <div class="warning"><strong class="warning">警告</strong>
   <p class="para">
    该函数自 PHP 8.1.0 起<em class="emphasis">弃用</em>。强烈建议不要依赖此函数。请改用 <span class="function"><a href="function.date-sun-info.html" class="function">date_sun_info()</a></span>。
   </p>
  </div>
 </div>

 <div class="refsect1 description" id="refsect1-function.date-sunrise-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>date_sunrise</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$timestamp</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$returnFormat</code><span class="initializer"> = <strong><code>SUNFUNCS_RET_STRING</code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">?</span><span class="type"><span class="type">float</span><span class="type"></span></span> <code class="parameter">$latitude</code><span class="initializer"> = <strong><code>null</code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">?</span><span class="type"><span class="type">float</span><span class="type"></span></span> <code class="parameter">$longitude</code><span class="initializer"> = <strong><code>null</code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">?</span><span class="type"><span class="type">float</span><span class="type"></span></span> <code class="parameter">$zenith</code><span class="initializer"> = <strong><code>null</code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">?</span><span class="type"><span class="type">float</span><span class="type"></span></span> <code class="parameter">$utcOffset</code><span class="initializer"> = <strong><code>null</code></strong></span></span><br>): <span class="type"><span class="type">string</span>|<span class="type">int</span>|<span class="type">float</span>|<span class="type"><span class="type false">false</span></span></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>date_sunrise()</strong></span> 返回给定的日期（以
   <code class="parameter">timestamp</code> 指定）与地点的日出时间。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.date-sunrise-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">timestamp</code></dt>

     <dd>

      <p class="para">       
       取 <code class="parameter">timestamp</code>所在日期的日出时间。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">returnFormat</code></dt>

     <dd>

      <p class="para">
       <table class="doctable table">
        <caption><strong><code class="parameter">returnFormat</code> 常量</strong></caption>
        
         <thead>
          <tr>
           <th>常量</th>
           <th>说明</th>
           <th>取值举例</th>
          </tr>

         </thead>

         <tbody class="tbody">
          <tr>
           <td>SUNFUNCS_RET_STRING</td>
           <td>以 <span class="type">string</span> 格式返回结果</td>
           <td>16:46</td>
          </tr>

          <tr>
           <td>SUNFUNCS_RET_DOUBLE</td>
           <td>以 <span class="type">float</span> 格式返回结果</td>
           <td>16.78243132</td>
          </tr>

          <tr>
           <td>SUNFUNCS_RET_TIMESTAMP</td>
           <td>以 <span class="type">int</span> 格式（时间戳）返回结果</td>
           <td>1095034606</td>
          </tr>

         </tbody>
        
       </table>

      </p>
     </dd>

    
    
     <dt>
<code class="parameter">latitude</code></dt>

     <dd>

      <p class="para">
       默认是指北纬。因此如果要指定南纬，必须传递一个负值。
       参见 <a href="datetime.configuration.html#ini.date.default-latitude" class="link">date.default_latitude</a>
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">longitude</code></dt>

     <dd>

      <p class="para">
       默认是指东经。因此如果要指定西经，必须传递一个负值。
       参见 <a href="datetime.configuration.html#ini.date.default-longitude" class="link">date.default_longitude</a>
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">zenith</code></dt>

     <dd>

      <p class="para">
       <code class="parameter">zenith</code> is the angle between the center of the sun
       and a line perpendicular to earth&#039;s surface. It defaults to
       <a href="datetime.configuration.html#ini.date.sunrise-zenith" class="link">date.sunrise_zenith</a>
       <table class="doctable table">
        <caption><strong>Common <code class="parameter">zenith</code> angles</strong></caption>
        
         <thead>
          <tr>
           <th>Angle</th>
           <th>Description</th>
          </tr>

         </thead>

         <tbody class="tbody">
          <tr>
           <td>90°50&#039;</td>
           <td>Sunrise: the point where the sun becomes visible.</td>
          </tr>

          <tr>
           <td>96°</td>
           <td>Civil twilight: conventionally used to signify the start of dawn.</td>
          </tr>

          <tr>
           <td>102°</td>
           <td>Nautical twilight: the point at which the horizon starts being visible at sea.</td>
          </tr>

          <tr>
           <td>108°</td>
           <td>Astronomical twilight: the point at which the sun starts being the source of any illumination.</td>
          </tr>

         </tbody>
        
       </table>

      </p>
     </dd>

    
    
     <dt>
<code class="parameter">utcOffset</code></dt>

     <dd>

      <p class="para">
       单位是小时。
       The <code class="parameter">utcOffset</code> is ignored, if
       <code class="parameter">returnFormat</code> is
       <strong><code>SUNFUNCS_RET_TIMESTAMP</code></strong>.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.date-sunrise-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   按指定格式 <code class="parameter">returnFormat</code> 返回的日出时间， 或者在失败时返回 <strong><code>false</code></strong>。
   One potential reason for failure is that the
   sun does not rise at all, which happens inside the polar circles for part of
   the year.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-function.date-sunrise-errors">
  <h3 class="title">错误／异常</h3>
   
   <p class="para">
在每次调用日期/时间函数时，如果时区无效则会引发 <strong><code>E_NOTICE</code></strong> 错误。参见
<span class="function"><a href="function.date-default-timezone-set.html" class="function">date_default_timezone_set()</a></span>。</p>
 
 </div>


 <div class="refsect1 changelog" id="refsect1-function.date-sunrise-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>8.1.0</td>
       <td>
        此函数已弃用，请改用 <span class="function"><a href="function.date-sun-info.html" class="function">date_sun_info()</a></span>。
       </td>
      </tr>

      <tr>
       <td>8.0.0</td>
       <td>
        <code class="parameter">latitude</code>, <code class="parameter">longitude</code>,
        <code class="parameter">zenith</code> and <code class="parameter">utcOffset</code> are nullable now.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.date-sunrise-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-2086">
    <p><strong>示例 #1 <span class="function"><strong>date_sunrise()</strong></span> 例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">/*&nbsp;计算葡萄牙里斯本的日出时间<br />Latitude:&nbsp;&nbsp;北纬&nbsp;38.4&nbsp;度<br />Longitude:&nbsp;西经&nbsp;9&nbsp;度<br />Zenith&nbsp;~=&nbsp;90<br />offset:&nbsp;+1&nbsp;GMT<br />*/<br /><br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"D&nbsp;M&nbsp;d&nbsp;Y"</span><span style="color: #007700">).&nbsp;</span><span style="color: #DD0000">',&nbsp;sunrise&nbsp;time&nbsp;:&nbsp;'&nbsp;</span><span style="color: #007700">.</span><span style="color: #0000BB">date_sunrise</span><span style="color: #007700">(</span><span style="color: #0000BB">time</span><span style="color: #007700">(),&nbsp;</span><span style="color: #0000BB">SUNFUNCS_RET_STRING</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">38.4</span><span style="color: #007700">,&nbsp;-</span><span style="color: #0000BB">9</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">90</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Mon Dec 20 2004, sunrise time : 08:54
</pre></div>
    </div>
   </div>
   <div class="example" id="example-2087">
    <p><strong>示例 #2 No sunrise</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$solstice&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">strtotime</span><span style="color: #007700">(</span><span style="color: #DD0000">'2017-12-21'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">date_sunrise</span><span style="color: #007700">(</span><span style="color: #0000BB">$solstice</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">SUNFUNCS_RET_STRING</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">69.245833</span><span style="color: #007700">,&nbsp;-</span><span style="color: #0000BB">53.537222</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
bool(false)
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.date-sunrise-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.date-sun-info.html" class="function" rel="rdfs-seeAlso">date_sun_info()</a> - Returns an array with information about sunset/sunrise and twilight begin/end</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>